package company.面试考题.huawei;

import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;

/**
 * @author Liu.Liangyuan 15439
 * @version $Id: Problem.java, v 0.1 2022年03月06日 2:02 下午 Liangmu Exp $$
 */
public class OD {

    public static void main(String[] args) {
        int[] ints = {9 , 10 };
        System.out.println(fun1(ints));
    }

    public static String fun1(int[] req) {
        if (req.length == 0) return "";
        // 排序
        StringBuilder result = new StringBuilder();
        // 将 req 转为字符串
        List<String> strings = Arrays.stream(req).mapToObj(String::valueOf).sorted(
            (v1, v2) -> {
                int k = v1.compareTo(v2);
                if (k == 0) return 0;
                if (k < 0) return v2.startsWith(v1) ? 1 : -1;
                return v1.startsWith(v2) ? -1 : 1;
            }
        ).collect(Collectors.toList());
        int len = strings.size();
        for (int i = len - 1; i >= 0; --i) {
            result.append(strings.get(i));
        }
        String k = result.toString().replaceAll("0", "");
        if (k.length() == 0) {
            return "0";
        }
        return result.toString();
    }

    public static int fun2() {
        Scanner scanner = new Scanner(System.in);
        int len = scanner.nextInt();
        int[] ints = new int[len];
        for (int i = 0; i < len; i++) {
            ints[i] = scanner.nextInt();;
        }
        int n = scanner.nextInt();
        // 用来判断是不是重叠
        if (n * 2 > len) {
            return -1;
        }
        // 排序
        Arrays.sort(ints);
        int result = 0;
        int len2 = len - 1;
        // 求和
        for (int i = 0; i < n; ++i) {
            result += ints[i];
            result += ints[len2 - i];
        }
        return result;
    }

    public static Long fun3(long[] req) {
        int len = req.length;
        long result = 0L;
        for (int s = 0; s < len; s++) {
            for (int e = s; e < len; e++) {
                result = Math.max(Math.min(req[s], req[e]) * (e-s), result);
            }
        }
        return result;
    }
}
